import bisect
class Solution(object):
    def numFriendRequests(self, ages):
        """
        :type ages: List[int]
        :rtype: int
        """
        ages.sort()
        n = len(ages)
        t = 0
        for i in range(n):
            if ages[i] > 14:
                right = bisect.bisect_right(ages, ages[i])
                left = bisect.bisect_right(ages, 0.5 * ages[i] + 7)
                t += right - left - 1
        return t



data = Solution()
ages = [20, 30, 100, 110, 120]
print(data.numFriendRequests(ages))
